#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define D long double
#define N 452
ll dp[N][100005],qz[N];
signed main(){
	freopen("moon.in","r",stdin);
	freopen("moon.out","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int q,mod;cin>>q>>mod;
	for(int i=0;i<=100000;i++)	dp[1][i]=1;
	for(int i=2;i<=448;i++){
		for(int j=0;j<i;j++)	qz[j]=0;
		for(int j=0;j<=100000;j++){
			qz[j%i]=(qz[j%i]+dp[i-1][j])%mod;
		}
		for(int j=100000;j>=0;j--){
			dp[i][j]=qz[j%i];qz[j%i]=(((qz[j%i]-dp[i-1][j])%mod+mod)%mod);
		}
	}
	while(q--){
		int n;cin>>n;
		ll sum=0;
		for(int i=1;i*i<=n;i++){
			int v=n-i*i;
			if(v&1)	continue;
			sum=(sum+dp[i][v/2])%mod;
		}
		cout<<sum<<"\n";
	}
	return 0;
}
/*
dp[i][j]:j things into i groups,can be null,go up
*/
